package com.aipp.mall.h5.controller;

import com.aipp.mall.common.anno.Note;
import com.aipp.mall.common.model.Query;
import com.aipp.mall.common.utils.Result;
import com.aipp.mall.common.utils.SecurityUtil;
import com.aipp.mall.h5.domain.dto.DeliveryReq;
import com.aipp.mall.h5.domain.form.*;
import com.aipp.mall.h5.domain.vo.*;
import com.aipp.mall.h5.service.H5OrderService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 订单接口
 *
 * @author Administrator
 */
@Slf4j
@RestController
@RequestMapping("/h5/order")
public class H5OrderController {

    @Resource
    private H5OrderService h5OrderService;

    @Note("下单")
    @PostMapping("/add")
    public Result<Long> submit(@RequestBody OrderSubmitForm form) {
        return Result.ok(h5OrderService.submit(form));
    }

    @Note("下单前校验")
    @PostMapping("/addOrderCheck")
    public Result<OrderCalcVO> addOrderCheck(@RequestBody OrderCreateForm orderCreateForm) {
        return Result.ok(h5OrderService.addOrderCheck(orderCreateForm));
    }

    @Note("订单列表")
    @GetMapping("/page")
    public Result<IPage<H5OrderVO>> orderPage(Integer status, Query query) {
        return Result.ok(h5OrderService.orderPage(status, query));
    }

    @Note("订单详情")
    @GetMapping("/orderDetail")
    public Result<H5OrderVO> orderDetail(@RequestParam Long orderId) {
        return Result.ok(h5OrderService.orderDetail(orderId));
    }

    @Note("确认收货")
    @GetMapping("/orderComplete")
    public Result<String> orderComplete(Long orderId) {
        return Result.ok(h5OrderService.orderComplete(orderId));
    }

    @Note("订单数量统计")
    @GetMapping("/countOrder")
    public Result<CountOrderVO> orderNumCount() {
        return Result.ok(h5OrderService.orderNumCount(SecurityUtil.getMemberId()));
    }

    @Note("取消订单")
    @PostMapping("/orderCancel")
    public Result<String> orderCancel(@RequestBody CancelOrderForm request) {
        return Result.ok(h5OrderService.orderBatchCancel(request));

    }

    @Note("订单支付")
    @PostMapping("/orderPay")
    public Result<OrderPayVO> orderPay(@RequestBody OrderPayForm req) {
        return Result.ok(h5OrderService.orderPay(req));
    }

    @Note("申请售后")
    @PostMapping("/applyRefund")
    public Result<Boolean> applyRefund(@RequestBody ApplyRefundForm applyRefundForm) {
        return Result.ok(h5OrderService.applyRefund(applyRefundForm));
    }

    @Note("取消售后")
    @GetMapping("/cancelRefund")
    public Result<String> cancelRefund(Long orderId) {
        return Result.ok(h5OrderService.cancelRefund(orderId));
    }

    @Note("售后订单详情")
    @GetMapping("/refundOrderDetail")
    public Result<AfterSaleRefundInfoVO> refundOrderDetail(@RequestParam Long orderId) {
        return Result.ok(h5OrderService.refundOrderDetail(orderId));
    }

    @Note("用户提交退货单号")
    @PostMapping("/aftersale/delivery")
    public Result<String> delivery(@RequestBody @Valid DeliveryReq req) {
        return Result.ok(h5OrderService.delivery(req));
    }

}
